package com.bestcem.xm.om.grpc.service.converter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.om.constant.CommonConstant;
import com.bestcem.xm.om.grpc.service.dto.OrderDTO;
import com.bestcem.xm.om.grpc.service.param.UpgradePackageParam;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * 套餐grpc请求出入参转化类
 *
 * @author YiFang <yifang.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2022/7/6 11:34
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class OmPackageConverter {

        public static UpgradePackageParam orderDto2UpgradePackageParam(OrderDTO orderDTO){
            UpgradePackageParam param=new UpgradePackageParam();
            JSONObject extraJson = JSON.parseObject(orderDTO.getExtra());
            String activityCode = Objects.nonNull(extraJson.get("activity_code")) ? extraJson.get("activity_code").toString() : CommonConstant.ORDER_BUY_TYPE_DEFAULT;
            int packType=extraJson.getIntValue("pack_type");
            int duration=extraJson.getIntValue("duration");
            int durationUnit=extraJson.getIntValue("duration_unit");
            param.setOrder(orderDTO);
            param.setOrgId(orderDTO.getPayerOrgId());
            param.setOrderNo(orderDTO.getOrderNo());
            param.setActivityCode(activityCode);
            param.setPackageType(packType);
            param.setDuration(duration);
            param.setDurationUnit(durationUnit);
            return param;
        }
}
